/*
 * Kpatch module
 *
 * The core code comes from tpatch, the early hot patch tool of tlinux.
 *
 */
#ifndef _KPROBE_PREHOOK_H
#define _KPROBE_PREHOOK_H

#include "hook_tk5.h"

#define MAX_SYMBOL_LEN	64
#ifdef TK5
#define FUNCTION_PRINT_FORMAT "%pS"
#else
#define FUNCTION_PRINT_FORMAT "%pF"
#endif
#ifdef TK3
#define NAME_MAX 255
#endif

#define HOOK_FUNC_NUM 50
/* per-instance private data */
struct kret_data {
	unsigned long nr;
	unsigned long num;
	unsigned long time[8];
};

extern struct work_struct ftrace_work;
extern struct work_struct ftrace_work_init;
extern int register_kretprobe_ftrace;
extern int register_ftrace_ftrace;
extern char ftrace_hook_name[NAME_MAX];
extern char func_name_new[NAME_MAX];
extern unsigned int sysctl_kprobe_unregister;
extern char symbol_new[NAME_MAX];
extern char symbol_kret_new[NAME_MAX];
extern unsigned long stat_func_total_time[HOOK_FUNC_NUM];
extern unsigned long stat_func_total_num[HOOK_FUNC_NUM];
extern unsigned long stat_one_func_size;

extern int kprobe_init(void);
extern void kprobe_exit(void);
extern int kretprobe_init(void);
extern void kretprobe_exit(void);
extern bool print_func_name(void *opt, void *opt2, void *opt3, char *pointer, char *func);
extern void print_info(void *opt, void *opt2, void *opt3);
extern char func_pointer[NAME_MAX];
extern char func_pointer_name[NAME_MAX];
extern char printk_name_first[NAME_MAX];
extern char printk_name_last[NAME_MAX];
extern void ftrace_unhook_work_fn(struct work_struct *work);
extern void ftrace_hook_work_fn(struct work_struct *work);
extern bool sub_print_func_name(void *opt, void *opt2, void *opt3, char *pointer, char *func);
extern bool check_func_name(char *func);
extern unsigned long *stat_one_func_time;
extern void save_sched_in(void);
extern void save_sched_out(void);
extern void stat_total_time(void);
extern char *get_one_func_name(int i);
extern void save_start_time(int index);
extern void save_total_time(int index);
extern int register_kret_new_func_batch(int index, char* func_name);
extern void unregister_kret_new_func_batch(int index);

extern int ftrace_patch_init(char *name);
extern void ftrace_patch_exit(void);
#endif
